package com.gaoh.thread.daemon;

import java.util.concurrent.TimeUnit;

/**
 * @author gaoh
 * @Description
 * @create 2021-12-18 上午10:29
 */
public class DaemonThreadTest {

    public static void main(String[] args) {

        Thread thread = new Thread(() -> {
            while (true) {
                try {
                    TimeUnit.MILLISECONDS.sleep(500);
                    System.out.println(System.currentTimeMillis());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });

        thread.setDaemon(true);

        thread.start();

        try {
            System.out.println(thread.getState());
            TimeUnit.MILLISECONDS.sleep(1000 * 2);
            System.out.println(thread.getState());

        } catch (InterruptedException e) {
            e.printStackTrace();
        }

    }
}
